<?php 
namespace Admin\Controller;
use Think\Controller;
class UserController extends CommonController{
	public function admin_login(){
		if(IS_POST){
			// 接受数据
			$data = I('Post.');
			// 验证验证码
			$verify = new \Think\Verify();
			$res = $verify->check($data['code']);
			if($res){
				$m = M('admin');
				unset($data['code']);
				unset($data['send']);
				unset($data['__hash__']);
				// dump($data);die;
				$data['admin_pass'] = md5($data['admin_pwd']);
				// dump($data);die;
				$data = $m->where($data)->find();
				// dump($data);die;
				if($data){
					session('admin_name',$data['admin_name']);
					session('id',$data['admin_id']);
					// dump($data);die;
					$login_count=$data['login_count'];
					$login_count++;
					$info['admin_id']=$data['id'];
					$info['admin_login_count']=$login_count;
					$info['admin_last_ip']=$_SERVER['REMOTE_ADDR'];
					$info['admin_last_time']=time();
					$m->save($info);
					$this->success('登录成功!',U('Admin/Index/index'));
				}else{
					$this->error('用户名密码错误!');
				}

			}else{
				$this->error('验证码错误!');
			}

		}else{
			$this->display();
		}
		
	}

	public function captcha(){
		// 配置
		$config =	array(
			'fontSize'  =>  25,              // 验证码字体大小(px)
	        'useCurve'  =>  false,            // 是否画混淆曲线
	        'useNoise'  =>  false,            // 是否添加杂点	
	        'imageH'    =>  0,               // 验证码图片高度
	        'imageW'    =>  0,               // 验证码图片宽度
	        'length'    =>  4,               // 验证码位数
	        'fontttf'   =>  '4.ttf',              // 验证码字体，不设置随机获取
		);
		// 实例化验证码类
		$verify = new \Think\Verify($config);

		// 输出验证码
		$verify ->entry();
	}

	public function logout(){
		session(null);
		$this->redirect('Admin/User/admin_login','',1,'退出成功');
	}

}